<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
	<title>商品详情</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		.table td {
			vertical-align: middle;
		}
		.footer {
			position:fixed; bottom:0; background:#ABABAB; width:100%; height:35px; line-height:32px; z-index:9999; opacity:1;
			filter:alpha(opacity=60); _bottom:auto; _width:100%; _position:absolute;text-align: right;
			_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-
			(parseInt(this.currentStyle.marginTop, 10)||0)-(parseInt(this.currentStyle.marginBottom, 10)||0)));
	    }
	    .form-horizontal .controls {
		    margin-left: 130px;
		}
		.form-horizontal .control-label {
		    width: 120px;
		}
		#productModul li a{padding-top: 0px; padding-bottom: 0px;}
	</style>
	<script type="text/javascript">
		var remarksEditor
		KindEditor.ready(function(K) {
			if($('textarea[name="remarks"]')){
				remarksEditor = K.create('textarea[name="remarks"]', {
					cssPath : '<%=basePath %>/static/kindeditor/plugins/code/prettify.css',
					uploadJson : '<%=basePath %>/kindeditor/upload',
					allowFileManager : false,
					allowImageRemote : false,
					formatUploadUrl : false,
					cssPath:"<%=basePath %>/static/front/css/kindeditoriframe-user.css",
					afterCreate : function() {
						var self = this;
						K.ctrl(document, 13, function() {
							self.sync();
							//document.forms['example'].submit();
						});
						K.ctrl(self.edit.doc, 13, function() {
							self.sync();
							//document.forms['example'].submit();
						});
					}
				});
				prettyPrint();
			}
		});
		$(document).ready(function() {
			var nodeLen = $(".jbox-button-panel", top.document).length;
			$(".jbox-button-panel", top.document).eq(nodeLen-1).remove();
			if('${type}'!=''){
				parent.mainFrame.location.reload();
				top.$.jBox.close();
				document.location="${ctx}/ivm/product";
			}
			showInfo(0);
			$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				rules: {
					weight:{  positiveinteger:true}
				},   
				message:{
					weight:{  positiveinteger:"请输入正整数"}
				},   
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		
		//切换模块：商品信息、销售信息、管理信息
		function showInfo(type){
			$("#productModul li").each(function(){
				$(this).removeClass("active");
			});
			$("#productModul li").eq(type).addClass("active");
			$("#productInfo").hide();
			$("#saleInfo").hide();
			$("#managerInfo").hide();
			if(type==0){
				$("#productInfo").show();
			}else if(type==1){
				$("#saleInfo").show();
			}else{
				$("#managerInfo").show();
			}
		}
		//删除商品
		function delProduct(id){
			if(confirmx("确认要删除该商品吗？")){
				$('#inputForm').submit();
			}
		}
	</script>
</head>
<body>
<form:form id="inputForm" modelAttribute="product" action="${ctx}/ivm/product/saveProduct" method="post" class="form-horizontal" style="margin-bottom:30px">
	<form:hidden path="id"/>
	<form:hidden path="code"/>
	<form:hidden path="merchant.id"/>
	<tags:message content="${message}"/>
	<ul class="nav nav-tabs breadcrumb form-search" id="productModul">
		<li class="active"><a onclick="showInfo(0)">商品信息</a></li>
		<li><a onclick="showInfo(1)">销售信息</a></li>
		<li><a onclick="showInfo(2)">管理信息</a></li>
	</ul>
	<div id="productInfo">
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20">*</span>商品名称:</label>
			<div class="controls">
				<input id="oldName" name="oldName" type="hidden" value="${product.name}">
				<form:input path="name" htmlEscape="false" maxlength="200" class="required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">副标题:</label>
			<div class="controls">
				<form:input path="assisTitle" htmlEscape="false" maxlength="200" cssStyle="width: 450px;" class="input-xxlarge measure-input valid"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20">*</span>商品规格:</label>
			<div class="controls">
				<form:input path="spec" htmlEscape="false" maxlength="200" class="required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20">*</span>商品图片:</label>
			<div class="controls">
				<form:hidden path="logoUrl" />
				<div class="photo" style="width:149px; height:84px;">
					<c:if test="${product.logoUrl!=null && product.logoUrl!=''}">
						<img id="cutPhoto" src="${ctx}/download?filePath=${product.logoUrl }" style="width:149px; height:84px;" />
					</c:if>
					<c:if test="${product.logoUrl==null || product.logoUrl==''}">
						<img id="cutPhoto" src="" style="width:149px; height:84px;" />
					</c:if>
				</div>
				<a href="javascript:" class="btn" id="cutPhotoUpload">上传图片</a>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">购买须知:</label>
			<div class="controls">
				<form:textarea path="shouldKnow" htmlEscape="false" rows="4" maxlength="200" class="input-xxlarge"/>
				<br/><span style="color: red;">(提示：如需换行请输入&lt;br/&gt;)</span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">商品简介:</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="200" class="input-xxlarge" style="height: 320px;"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20">*</span>分类:</label>
			<div class="controls towClassify">
				<form:select path="classifyIdList" class="required">
					<form:options items="${fns:getAllClassifyTwoList()}" itemValue="id" itemLabel="name" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20">*</span>状态:</label>
			<div class="controls">
				<form:radiobuttons path="openState" items="${fns:getDictList('open_state')}" itemLabel="label" itemValue="value" htmlEscape="false" class="required" />
			</div>
		</div>
	</div>
	<div id="saleInfo">
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20">*</span>单价:</label>
			<div class="controls">
				<form:input path="price" htmlEscape="false" class="required number decimal"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20">*</span>单位:</label>
			<div class="controls">
				<form:select id="productUnit" path="productUnit.id" class="required" onchange="changeUnit(this)">
					<form:option value="" label="请选择"/>
					<form:options items="${fns:getUnitList()}" itemLabel="longName" itemValue="id" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">起购数量:</label>
			<div class="controls">
				<form:input path="startSaleNum" htmlEscape="false" class="digits" min="1" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">限购数量:</label>
			<div class="controls">
				<form:input path="purchaseNum" htmlEscape="false" class="digits" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20">*</span>是否支持到付:</label>
			<div class="controls">
				<form:radiobuttons path="toPay" items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false" class="required" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20">*</span>购物车有效时间:</label>
			<div class="controls">
				<form:input path="effectiveTime" htmlEscape="false" class="required" />
			</div>
		</div>
	</div>
	<div id="managerInfo">
		<div class="control-group">
			<label class="control-label">市场价:</label>
			<div class="controls">
				<form:input path="marketPrice" htmlEscape="false" class="number decimal"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">市场价跟价对象:</label>
			<div class="controls">
				<form:input path="marketPriceTarget" htmlEscape="false"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">供应商:</label>
			<div class="controls towClassify">
				<form:select path="supplierIdList" onchange="setDefSupplierOption()">
					<form:options items="${fns:getSupplierList()}" itemValue="id" itemLabel="name" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">摸价周期:</label>
			<div class="controls">
				<form:input path="collectPriceCycle" htmlEscape="false" maxlength="200" class="digits number input-small"/> &nbsp;天
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">定价标签:</label>
			<div class="controls">
				<form:input path="" htmlEscape="false"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">控制标签:</label>
			<div class="controls">
				<form:input path="" htmlEscape="false"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">分类标签:</label>
			<div class="controls">
				<form:input path="" htmlEscape="false"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">库存状态:</label>
			<div class="controls">
				<form:input path="stockState" htmlEscape="false"/>
			</div>
		</div>
	</div>
</form:form>
<!--endprint-->
<div class="footer" id="printDiv">
	<input value="删除商品" type="button" class="btn btn-primary" style="margin-right: 20px;" onclick="return confirmx('确认要删除该商品吗？', delProduct('${product.id}'))"/>
	<input value="保存修改" type="button" class="btn btn-primary" style="margin-right: 20px;" onclick="$('#type').val(1);$('#inputForm').submit();"/>
</div>
</body>
</html>